<%= if not is_nil(@changeset.data.bigquery_project_id) do %>
  <%= form_for @changeset, Routes.user_path(@conn, :update), fn e -> %>
  <div class="form-group">
    <%= text_input e, :bigquery_project_id, placeholder: "your-project-name", class: "form-control form-control-margin", readonly: true %>
    <%= error_tag e, :bigquery_project_id %>
    <small class="form-text text-muted">
      Your Google Cloud Platform project ID.
    </small>
    <%= text_input e, :bigquery_dataset_id, placeholder: "wobbly_wombat", class: "form-control form-control-margin", readonly: true %>
    <%= error_tag e, :bigquery_dataset_id %>
    <small class="form-text text-muted">
      Optional. Your dataset name. Alphanumberic string, and underscores are valid. Creates a new dataset if it doesn't exist.
    </small>
    <%= text_input e, :bigquery_dataset_location, placeholder: "US", class: "form-control form-control-margin", readonly: true %>
    <%= error_tag e, :bigquery_dataset_location %>
    <small class="form-text text-muted">
      Optional. Defaults to `US`. Your preferred dataset location. See the BigQuery documention for a <%= link "list of supported regions", to: "https://cloud.google.com/bigquery/docs/locations" %>. Use `Region Name` or `Multi-Region Name`.
    </small>
    <%= text_input e, :bigquery_processed_bytes_limit, placeholder: "1000000000", class: "form-control form-control-margin", readonly: true %>
    <%= error_tag e, :bigquery_dataset_location %>
    <small class="form-text text-muted">
      Optional. Set the processed bytes limit for queries. Defaults to 10 GB (10000000000 bytes).
    </small>

    <%= text_input e, :bigquery_reservation_search, placeholder: "projects/1234567890/reservations/1234567890", class: "form-control form-control-margin", readonly: true %>
    <%= error_tag e, :bigquery_reservation_search %>
    <small class="form-text text-muted">
      Optional. Set the reservation for search queries.
    </small>


    <%= text_input e, :bigquery_reservation_alerts, placeholder: "projects/1234567890/reservations/1234567890", class: "form-control form-control-margin", readonly: true %>
    <%= error_tag e, :bigquery_reservation_alerts %>
    <small class="form-text text-muted">
      Optional. Set the reservation for alerts queries.
    </small>


    <div class="form-check">
      <%= checkbox e, :bigquery_enable_managed_service_accounts, class: "form-check-input" %>
      <%= label e, :bigquery_enable_managed_service_accounts, "Enable managed service accounts", class: "form-check-label" %>
    </div>
    <%= error_tag e, :bigquery_enable_managed_service_accounts %>
    <small class="form-text text-muted">
      Optional. Enable routing API requests through managed service accounts for queries made to BigQuery.
      Requires the <code>resourcemanager.projects.setIamPolicy</code> permission on the project.
    </small>
  </div>
  <%= submit "Update BigQuery settings", class: "btn btn-primary form-button" %>
<% end %>
<%= form_for @changeset, Routes.user_path(@conn, :update), fn e -> %>
<%= hidden_input e, :bigquery_project_id, value: nil %>
<%= hidden_input e, :bigquery_dataset_id, value: nil %>
<%= hidden_input e, :bigquery_dataset_location, value: nil %>
<%= hidden_input e, :bigquery_reservation_search, value: nil %>
<%= hidden_input e, :bigquery_reservation_alerts, value: nil %>
<%= hidden_input e, :bigquery_processed_bytes_limit, value: 10_000_000_000 %>
<%= hidden_input e, :bigquery_enable_managed_service_accounts, value: false %>
<%= submit "Reset BigQuery settings", class: "btn btn-secondary form-button" %>
<% end %>
<% else %>
  <%= form_for @changeset, Routes.user_path(@conn, :update), fn e -> %>
  <div class="form-group">
    <%= text_input e, :bigquery_project_id, placeholder: "your-project-name", class: "form-control form-control-margin" %>
    <%= error_tag e, :bigquery_project_id %>
    <small class="form-text text-muted">
      Your Google Cloud Platform project ID.
    </small>
    <%= text_input e, :bigquery_dataset_id, placeholder: "wobbly_wombat", class: "form-control form-control-margin" %>
    <%= error_tag e, :bigquery_dataset_id %>
    <small class="form-text text-muted">
      Optional. Your dataset name. Alphanumberic string, and underscores are valid. Creates a new dataset if it doesn't exist.
    </small>
    <%= text_input e, :bigquery_dataset_location, placeholder: "US", class: "form-control form-control-margin" %>
    <%= error_tag e, :bigquery_dataset_location %>
    <small class="form-text text-muted">
      Optional. Defaults to `US`. Your preferred dataset location. See the BigQuery documention for a <%= link "list of supported regions", to: "https://cloud.google.com/bigquery/docs/locations" %>. Use `Region Name` or `Multi-Region Name`.
    </small>


    <%= text_input e, :bigquery_reservation_search, placeholder: "projects/1234567890/reservations/1234567890", class: "form-control form-control-margin" %>
    <%= error_tag e, :bigquery_reservation_search %>
    <small class="form-text text-muted">
      Optional. Set the reservation for search queries.
    </small>


    <%= text_input e, :bigquery_reservation_alerts, placeholder: "projects/1234567890/reservations/1234567890", class: "form-control form-control-margin" %>
    <%= error_tag e, :bigquery_reservation_alerts %>
    <small class="form-text text-muted">
      Optional. Set the reservation for alerts queries.
    </small>


    <%= text_input e, :bigquery_processed_bytes_limit, placeholder: "1000000000", class: "form-control form-control-margin" %>
    <%= error_tag e, :bigquery_dataset_location %>
    <small class="form-text text-muted">
      Optional. Set the processed bytes limit for queries. Defaults to 10 GB (10000000000 bytes).
    </small>
    <div class="form-check">
      <%= checkbox e, :bigquery_enable_managed_service_accounts, class: "form-check-input" %>
      <%= label e, :bigquery_enable_managed_service_accounts, "Enable managed service accounts", class: "form-check-label" %>
    </div>
    <%= error_tag e, :bigquery_enable_managed_service_accounts %>
    <small class="form-text text-muted">
      Optional. Enable routing API requests through managed service accounts for queries made to BigQuery.
      Requires the <code>resourcemanager.projects.setIamPolicy</code> permission on the project.
    </small>
  </div>
  <%= submit "Update BigQuery settings", class: "btn btn-primary form-button" %>
<% end %>
<% end %>
